import { request } from '@/utils/request'
import type { ApiResponse } from '@/utils/request'

// 学生查询参数接口
export interface StudentQuery {
  studentCode?: string
  studentName?: string
  classId?: number
  gender?: string
  idCard?: string
  contactPhone?: string
  studentStatus?: string
  pageNum: number
  pageSize: number
}

// 学生信息接口
export interface StudentForm {
  id?: number
  classId: number
  studentCode: string
  studentName: string
  gender?: string
  studentPicture?: string
  idCard?: string
  birthDate?: string
  admissionDate?: string
  expectedGraduationDate?: string
  nationality?: string
  politicalStatus?: string
  nativePlace?: string
  householdRegister?: string
  currentAddress?: string
  contactPhone?: string
  email?: string
  guardianName?: string
  guardianPhone?: string
  guardianRelationship?: string
  healthStatus?: string
  studentSource?: string
  enrollmentType?: string
  studentStatus?: string
  profilePhoto?: string
  idCardFront?: string
  idCardBack?: string
}

// 学生详细信息接口
export interface StudentInfo extends StudentForm {
  className?: string
  createdTime?: string
  updatedTime?: string
}

// 学生分页结果接口
export interface StudentPageResult {
  records: StudentInfo[]
  total: number
  size: number
  current: number
  pages: number
}

/**
 * 查询学生列表
 * @param query 查询参数
 * @returns 学生列表
 */
export function listStudent(query: StudentQuery) {
  return request.post<ApiResponse<StudentPageResult>>('/api/school/student/list', query)
}

/**
 * 获取学生详细信息
 * @param id 学生ID
 * @returns 学生信息
 */
export function getStudent(id: number) {
  return request.get<ApiResponse<StudentInfo>>(`/api/school/student/${id}`)
}

/**
 * 新增学生
 * @param data 学生信息
 * @returns 结果
 */
export function addStudent(data: StudentForm) {
  return request.post<ApiResponse<number>>('/api/school/student', data)
}

/**
 * 修改学生信息
 * @param data 学生信息
 * @returns 结果
 */
export function updateStudent(data: StudentForm) {
  return request.put<ApiResponse<boolean>>('/api/school/student', data)
}

/**
 * 删除学生
 * @param id 学生ID
 * @returns 结果
 */
export function deleteStudent(id: number) {
  return request.delete<ApiResponse<boolean>>(`/api/school/student/${id}`)
}

/**
 * 批量删除学生
 * @param ids 学生ID数组
 * @returns 结果
 */
export function batchDeleteStudent(ids: number[]) {
  return request.delete<ApiResponse<boolean>>(`/api/school/student/batch`, ids)
}

/**
 * 获取学籍状态选项
 */
export function getStudentStatusOptions() {
  return [
    { value: 'ACTIVE', label: '在校' },
    { value: 'GRADUATED', label: '已毕业' },
    { value: 'SUSPENDED', label: '休学' },
    { value: 'TRANSFERRED', label: '转学' },
    { value: 'DROPPED', label: '退学' }
  ]
}

/**
 * 获取性别选项
 */
export function getGenderOptions() {
  return [
    { value: '男', label: '男' },
    { value: '女', label: '女' }
  ]
}

/**
 * 获取政治面貌选项
 */
export function getPoliticalStatusOptions() {
  return [
    { value: '群众', label: '群众' },
    { value: '共青团员', label: '共青团员' },
    { value: '党员', label: '党员' }
  ]
} 